/*
 * Bunisoft the Open Source Communications Company
 * Copyright 2006, Bunisoft Inc.,
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.teremail.panto;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * The content disposition for a body part.  The default is inline.  Any additional
 * parameters are start in parameters map.
 * 
 * @see org.buni.panto.ContentDiposition
 * @author Michael Barker
 *
 */
public class ContentDisposition extends ContentHeader {

    private static final Pattern PATTERN = Pattern.compile("Content-Disposition:(.*)", 
            Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    public static final ContentDisposition DEFAULT = new ContentDisposition();
    private final static ContentHeaderFactory<ContentDisposition> FACTORY = 
        new ContentHeaderFactory<ContentDisposition>() {
        
        public ContentDisposition create(String text, String type, String subType, 
                Map<String,String> parameters) {
            return new ContentDisposition(text, type, subType, parameters);
        }
    };

    public ContentDisposition(String text, String type, String subType, Map<String,String> params) {
        super(text, type, subType, params);
    }
    
    public ContentDisposition(String type, Map<String,String> params) {
        this(null, type, null, params);
    }
    
    public ContentDisposition() {
        this(null, "inline", null, new HashMap<String,String>(0));
    }
    
    /**
     * Parse a content disposition line.
     * 
     * @param line A line of text
     * @return The parsed ContentDisposition instance
     * @throws ParseException
     */
    public static ContentDisposition parse(String line) throws ParseException {
        return create(line, PATTERN, FACTORY);
    }
    
    @Override
    public String getName() {
        return "Content-Disposition";
    }
    
    @Override
    public String getDefaultParameter(String key) {
        return null;
    }    
}
